home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 32 / advsys.zip / ADVFIO.C < prev    next >
Text File  |  1987-06-27  |  995b  |  61 lines

  1. /* advfio.c - file i/o routines for the adventure compiler */
  2. /*
  3.     Copyright (c) 1986, by David Michael Betz
  4.     All rights reserved
  5. */
  6.  
  7. #define BSIZE    8192
  8.  
  9. /* global variables */
  10. long ad_foff;
  11.  
  12. /* local variables */
  13. static char buf[BSIZE];
  14. static int boff;
  15. static int fd;
  16.  
  17. ad_create(name)
  18.   char *name;
  19. {
  20.     /* create the file */
  21.     if (!advcreate(name,&fd))
  22.     advfatal("can't create output file");
  23.     
  24.     /* initialize the buffer and file offset */
  25.     ad_foff = 0L;
  26.     boff = 0;
  27. }
  28.  
  29. ad_close()
  30. {
  31.     ad_flush();
  32.     if (!advclose(fd))
  33.     advfatal("error closing output file");
  34. }
  35.  
  36. ad_putc(ch)
  37.   int ch;
  38. {
  39.     buf[boff++] = ch; ad_foff++;
  40.     if (boff >= BSIZE)
  41.     ad_flush();
  42. }
  43.  
  44. ad_seek(pos)
  45.   long pos;
  46. {
  47.     ad_flush();
  48.     if (!advseek(fd,pos,0))
  49.     advfatal("error positioning output file");
  50.     ad_foff = pos;
  51. }
  52.  
  53. ad_flush()
  54. {
  55.     if (boff) {
  56.     if (!advwrite(fd,buf,boff))
  57.         advfatal("error writing to output file");
  58.     boff = 0;
  59.     }
  60. }
  61.